
import * as cc from 'cc';
import { Loger } from '../../loger/Loger';
import { TweenEasing } from '../../utils/AnimationUtils';
const { ccclass, property,menu } = cc._decorator;

@ccclass
@menu("扩展组件/ComFloatAction")
export default class ComFloatAction extends cc.Component {

    //单次移动时间
    @property duration: number = 1;
    
    //移动距离
    @property dis: number = 20;
    

    private posY: number;
    private tween: any;
    onLoad() {
        this.posY = this.node.getComponent(cc.UITransform).node.position.y;
       
    }
    onEnable() {
        Loger.log("ComFloatAction 启动")
        this.node.getComponent(cc.UITransform).node.position.set(this.node.getComponent(cc.UITransform).node.position.x,this.posY - this.dis);
        this.tween = cc.tween(this.node)
            .show()
            .to(this.duration, { position: cc.v3(this.node.getComponent(cc.UITransform).node.position.x, this.posY + this.dis, 0) },{ easing: TweenEasing.backInOut })
            .call(()=>{
                this.node.active = false;
            })
            .start();
    }

    onDisable() {
        Loger.log("ComFloatAction 禁用")
        if (this.tween) {
            this.tween.stop();
            this.tween = null;
            
            this.node.getComponent(cc.UITransform).node.position.set(this.node.getComponent(cc.UITransform).node.position.x,this.posY);
            
        }
    }
}
